package com.biz.primus.ms.depot.api;

import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.model.depot.vo.FreightTemplateDetailRespVo;
import com.biz.primus.model.depot.vo.FreightTemplateUpdateReqVo;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.depot.service.FreightTemplateService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * FreightApiController
 *
 * @author JKLiues
 * @date 2017年11月03日
 */
@RestController
@RequestMapping("soa/freightService")
public class FreightApiController extends BaseApiController {

    private final FreightTemplateService freightTemplateService;

    @Autowired
    public FreightApiController(FreightTemplateService freightTemplateService) {
        this.freightTemplateService = freightTemplateService;
    }

    @ApiOperation("编辑运费模板")
    @PostMapping("editFreightTemplate")
    public void editFreightTemplate(@RequestBody FreightTemplateUpdateReqVo reqVo) {
        freightTemplateService.editFreightTemplate(reqVo);
    }

    @ApiOperation("更新运费模板可用状态")
    @PostMapping("changeStatus")
    public void changeStatus(@ApiParam(value = "运费模板ID") @RequestParam("id") Long id,
                             @ApiParam(value = "状态") @RequestParam("status") CommonStatus status) {
        freightTemplateService.changeStatus(id, status);
    }

    @ApiOperation("获取运费模板详情")
    @GetMapping("detail")
    public FreightTemplateDetailRespVo detail(@ApiParam(value = "运费模板ID") @RequestParam("id") Long id) {
        return freightTemplateService.detail(id);
    }

    @ApiOperation("校验运费木模板编号的唯一性")
    @PostMapping("checkCodeExists")
    public Boolean checkCodeExists(@ApiParam(value = "运费模板ID") @RequestParam("id") Long id,
                                   @ApiParam(value = "运费模板编码") @RequestParam("freightCode") String freightCode) {
        return freightTemplateService.checkCodeExists(id, freightCode);
    }

    @ApiOperation("获取总运费")
    @PostMapping("getPrice")
    public Integer getPrice(@ApiParam(value = "快递公司编号") @RequestParam("freightCode") String freightCode,
                            @ApiParam(value = "总重量") @RequestParam("totalWeight") Integer totalWeight) {
        return freightTemplateService.getPrice(freightCode, totalWeight);
    }
}